<?php
namespace app\admin\model;

use think\Db;
use think\Model;

class ReviewPhone extends Model
{
    public static function getListAll($request)
    {
        //检测表是否存在
        $tableName = 'bus_review_phone_' . $request['st'];
        // return Db::table($tableName)->select();

        $rableResult = Db::query('SHOW TABLES LIKE ' . "'" . $tableName . "'");

        if ($rableResult) {
            $where[] = ['table_order_id', 'eq', $request['tableId']];
            if ($request['phone'] != '') {
                $where[] = ['phone', 'eq', $request['phone']];
            }
            $data = Db::table($tableName)->where($where)
                ->paginate($request['limit'], false, $request)
                ->toarray();
            foreach ($data['data'] as $k => $v) {
                //查询渠道对应的通道
                switch ($v['isp']) {
                    case '10000':
                        $data['data'][$k]['isp'] = '电信';
                        break;
                    case '10086':
                        $data['data'][$k]['isp'] = '移动';
                        break;
                    case '10010':
                        $data['data'][$k]['isp'] = '联通';
                        break;
                    default:
                        $data['data'][$k]['isp'] = '未知';
                        break;
                }
            }
        } else {
            $data = [];
        }

        return $data;

    }

}
